//
//  MyViewController.m
//  ChickenA
//
//  Created by 韦显光 on 2018/7/2.
//  Copyright © 2018年 xg韦. All rights reserved.
//

#import "MyViewController.h"
#import "MsgCell.h"
#import "tabbarViewController.h"
#import "ZYLAlert.h"
#import "UIButton+WebCache.h"
#import "UIViewController+XHPhoto.h"
#import <SafariServices/SafariServices.h>
#import "IDAuthViewController.h"
@interface MyViewController ()
{
    NSArray*tbvdata;
}
@property (weak, nonatomic) IBOutlet UILabel *moneyLb;
@property (weak, nonatomic) IBOutlet UITableView *tbv;
@property (weak, nonatomic) IBOutlet UIButton *nameBtno;
@property (weak, nonatomic) IBOutlet WxgButton *faceBtno;
@property(nonatomic,strong)tabbarViewController*tabbarVC;
@property (weak, nonatomic) IBOutlet UIView *navback;
@end

@implementation MyViewController
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:NO];
//    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
}
//tag  1:名字  2头像  3简历
- (IBAction)Topbtna:(UIButton *)sender {
    if (sender.tag==3) {
        [MyUtils collviewSelidex:@"我的简历" toVc:self andShopInfo:nil];
//        [MyUtils collviewSelidex:@"新建简历" toVc:self andShopInfo:nil];
        
    }else if (sender.tag==2)
    {
        [self showCanEdit:YES photo:^(UIImage *photo) {
            NSData *imageData = UIImageJPEGRepresentation(photo, 0.5);;
            [FuncPublic  UpdataONEforimgdata:imageData FileName:@"headimg" Dict:nil Url:Xedit_avatar success:^(NSDictionary *acountInfo) {

                [WSProgressHUD showImage:nil status:@"上传成功"];
            }];
        }];
    }
    
}
- (IBAction)mingxiBtna:(UIButton *)sender {
     [MyUtils collviewSelidex:@"薪资明细" toVc:self andShopInfo:nil];
    
}
- (IBAction)BankBtna:(UIButton *)sender {
     [MyUtils collviewSelidex:@"银行卡" toVc:self andShopInfo:nil];
    
}
- (IBAction)GetCashBtna:(UIButton *)sender {
      [MyUtils collviewSelidex:@"提现列表" toVc:self andShopInfo:nil];
    
}


- (IBAction)StarastBtna:(UIButton *)sender {
     [MyUtils collviewSelidex:@"我的财产" toVc:self andShopInfo:nil];
}
//tag  1:收藏  2设置
- (IBAction)navBtna:(UIButton *)sender {
    if (sender.tag==2) {
        UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"jzHD" bundle:nil];
    UIViewController*secondViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:@"Setting"];
        [self.navigationController pushViewController:secondViewController animated:YES];
        

    }else
    {
        [MyUtils collviewSelidex:@"我的收藏" toVc:self andShopInfo:nil];
    }
    
}
- (IBAction)Btnas:(UIButton *)sender {
    NSArray*tempary=@[@"全部",@"我的收藏",@"邀面试",@"评价",@"浏览历史"];
    [MyUtils collviewSelidex:tempary[sender.tag] toVc:self andShopInfo:nil];
    
}


-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:NO];
     [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
     [self loadMydata];
}
-(void)loadMydata
{
 
    if (![WXGStr([FuncPublic GetDefaultInfo:@"token"])empty]) {
     
        [FuncPublic getData:self parameters:nil RequestUrl:Xuserinfo success:^(NSDictionary *acountInfo) {
            NSDictionary*dic=acountInfo[@"userinfo"];
            [FuncPublic SaveDefaultInfo:WXGStr(dic[@"phone"]) Key:@"myphone"];
             [ _nameBtno setTitle:[WXGStr(dic[@"nickname"]) empty]?@"请设置昵称":dic[@"nickname"] forState:UIControlStateNormal];
             _moneyLb.text=[NSString stringWithFormat:@"%@",dic[@"expense"]];
            [FuncPublic SaveDefaultInfo:[WXGStr(dic[@"nickname"]) empty]?@"注册名有误请联系管理员":dic[@"nickname"] Key:@"nickname"];
            if ([[dic allKeys]containsObject:@"headimg"]&&![WXGStr(dic[@"headimg"])empty]) {
                 [_faceBtno sd_setImageWithURL:[dic[@"headimg"]formatUrl] forState:UIControlStateNormal];
            }else
            {
                  [_faceBtno setImage:WXGImage(@"touxiang.jpg") forState:UIControlStateNormal];
            }
            

        }];

    }else
    {
        [ _nameBtno setTitle:@"请设置昵称" forState:UIControlStateNormal];
        [_faceBtno setImage:WXGImage(@"touxiang.jpg") forState:UIControlStateNormal];
        
        ZYLAlert *zylAlert = [[ZYLAlert alloc] initWithTitle:nil message:@"登录后才能使用"];
        [zylAlert addBtnAlertTitle:@"取消" action:^{
            self.tabbarVC.selectedIndex=0;
            
        }];
        [zylAlert addBtnAlertTitle:@"去登录" action:^{
            //隐私协议
            if (![FuncPublic GetDefaultInfo:@"SFSafariViewController"]) {
                SFSafariViewController *sfVC = [[SFSafariViewController alloc]initWithURL:[NSURL URLWithString:@"http://47.106.159.82/user_rules.html"]];
                [self presentViewController:sfVC animated:YES completion:nil];
                [FuncPublic SaveDefaultInfo:@"1" Key:@"SFSafariViewController"];
            }
            [MyUtils  IsLongin];
        }];
        
        [zylAlert showAlertWithSender:self];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    tbvdata=@[@"浏览历史",@"我的收藏",@"邀请好友",@"联系客服",@"投诉建议"];
  _tbv.separatorColor=[UIColor clearColor];
   _navback.backgroundColor=[[UIColor whiteColor]colorWithAlphaComponent:0];

    if (@available(iOS 11.0, *)){
        _tbv.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        _tbv.contentInset = UIEdgeInsetsMake(0, 0, 49, 0);
    }else
    {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark 返回每组行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  tbvdata.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    
    static NSString *ID = @"MsgCell";
    MsgCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.lb1.text=tbvdata[indexPath.row];
    return cell;

}


#pragma mark 设置每行高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}
#pragma mark 点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{
    NSString*str=tbvdata[indexPath.row];
    if ([str isEqualToString:@"邀请好友"]) {
         [MyUtils shareWindowOpen:@{@"title":@"我在职贝勒发现一个好职位也许适合你,快去看看吧",@"share_url":@"www.baidu.com",@"name":@"涵盖了各行各业，全职兼职。",@"company":@"各种企业直招，在线结算"}];
        return;
    }else if ([str isEqualToString:@"联系客服"]||[str isEqualToString:@"投诉建议"])
    {
        NSMutableString* str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",@"4006663186"];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
        return;
    }
    [MyUtils collviewSelidex:str toVc:self andShopInfo:nil];
    
}


-(tabbarViewController*)tabbarVC
{
    if (!_tabbarVC) {
        _tabbarVC=(tabbarViewController*)self.tabBarController;
    }
    return _tabbarVC;
}

- (IBAction)changgeName:(UIButton *)sender {
    
//    UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil
//                                                                   message:@"在这里输入新的昵称"
//                                                            preferredStyle:UIAlertControllerStyleAlert];
//
//    UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"修改" style:UIAlertActionStyleDefault
//                                                     handler:^(UIAlertAction * action) {
//                                                         if ([FuncPublic TextFieldisError:[alert.textFields firstObject]]) {
//                                                                     [FuncPublic getData:self parameters:@{@"nickname":[alert.textFields firstObject].text,@"random":@"1"} RequestUrl:Xeditname success:^(NSDictionary *acountInfo) {
//                                                                         [WSProgressHUD showWithStatus:@"修改成功" maskType:WSProgressHUDMaskTypeBlack];
//                                                                         [_nameBtno setTitle:[alert.textFields firstObject].text forState:UIControlStateNormal];
//                                                                     }];
//                                                         }
//                                                     }];
//    UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel
//                                                         handler:^(UIAlertAction * action) {
//
//                                                         }];
//    [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
//        textField.placeholder = @"请输入新昵称";
//
//    }];
//
//    [alert addAction:okAction];
//    [alert addAction:cancelAction];
//    [self presentViewController:alert animated:YES completion:nil];
    

    
}


@end
